package org.setaria.effect
{
	import flash.utils.Dictionary;
	
	import mx.effects.Effect;
	import mx.effects.Fade;
	import mx.effects.Parallel;
	import mx.events.EffectEvent;
	
	import spark.skins.spark.TitleWindowSkin;

	public class SetariaEffectPool
	{
		public static const DEFAULT_POPUP_EFFECT:String = "defaultPopUpEffect";
		public static const DEFAULT_REMOVE_EFFECT:String = "defaultRemoveEffect";
		
		public function SetariaEffectPool()
		{
		}
		/*存放需要使用的Effect*/
		private static var effects:Dictionary = new Dictionary();
		
		public static var defaultPopUpEffect:String;
		public static var defaultRemoveEffect:String;
		
		public static function getEffect(effectName:String):Effect{
			return effects[effectName] as Effect;
		}
		/**
		 * 添加效果
		 * */
		public static function addEffect(effect:Effect,effectName:String):void{
			effect.addEventListener(EffectEvent.EFFECT_END,function ():void{
				effect.stop();
				effect.target = null;
			});
			effects[effectName] = effect;
		}
		
		/**
		 * 初始化默认效果
		 * */
		public static function initDefaultEffect(popupDefaultEffect:Effect = null,removeDefaultEffect:Effect = null,popupEffectName:String = SetariaEffectPool.DEFAULT_POPUP_EFFECT,removeEffectName:String=SetariaEffectPool.DEFAULT_REMOVE_EFFECT):void{
			defaultPopUpEffect = popupEffectName;
			defaultRemoveEffect = removeEffectName;
			if(popupDefaultEffect){
				effects[defaultPopUpEffect] = popupDefaultEffect;
			}else{
				var popupEffect:Parallel = new Parallel();
				var e1:Fade = new Fade();
				e1.duration = 1000;
				e1.alphaFrom = 0;
				e1.alphaTo = 1;
				popupEffect.addChild(e1);
				addEffect(popupEffect,defaultPopUpEffect);
			}
			
			if(removeDefaultEffect){
				effects[defaultRemoveEffect] = removeDefaultEffect;
			}else{
				var removeEffect:Parallel = new Parallel();
				var e2:Fade = new Fade();
				e2.duration = 500;
				e2.alphaFrom = 1;
				e2.alphaTo = 0;
				removeEffect.addChild(e2);
				addEffect(removeEffect,defaultRemoveEffect);
			}
		}
	}
}